﻿namespace OverStore.Configuration.ComponentModel
{
    using OverStore.Runtime;
    using OverStore.Runtime.OverStoreContext;

    /// <summary>
    /// Configuration that produces new instance of <typeparamref name="TImplementation"/> class 
    /// on each call of <see cref="IComponentConfiguration{TInterface}.CreateComponent"/> method.
    /// </summary>
    /// <typeparam name="TInterface">The type of the interface.</typeparam>
    /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
    public class ActivatorConfiguration<TInterface, TImplementation> : IComponentConfiguration<TInterface>
        where TInterface : IRuntimeComponent
        where TImplementation : class, TInterface, new()
    {
        /// <summary>
        /// Singleton instance of <see cref="ActivatorConfiguration{TInterface, TImplementation}"/> class.
        /// </summary>
        public static readonly IComponentConfiguration<TInterface> Value = new ActivatorConfiguration<TInterface, TImplementation>();

        /// <summary>
        /// Initializes a new instance of the <see cref="ActivatorConfiguration&lt;TInterface, TImplementation&gt;"/> class.
        /// </summary>
        private ActivatorConfiguration() 
        { 
        }

        TInterface IComponentConfiguration<TInterface>.CreateComponent(IOverStoreContext context)
        {
            return new TImplementation();
        }
    }
}
